<?php
// $Id: application.php,v 1.6 2003/11/25 08:51:39 Yoshi.Sakai Exp $
require('header.php');
//global $xoopsConfigUser;	
	if(!$xoopsUser){
		redirect_header(XOOPS_URL.'/',1,_MD_POPNUPBLOG_NORIGHTTOACCESS.'(1.1)');
		exit();
	}
	if(!xoops_refcheck()){
		redirect_header(XOOPS_URL.'/modules/popnupblog/',2,'Referer Check Failed');
		exit();
	}
	if((!empty($xoopsModuleConfig['POPNUPBLOG_APPL'])) && ($xoopsModuleConfig['POPNUPBLOG_APPL'] == 1) ){
		redirect_header(XOOPS_URL.'/',1,_MD_POPNUPBLOG_NORIGHTTOACCESS.'(1.2)');
		exit();
	}
	$uname = $xoopsUser->getVar('uname');
	$canread    = isset($HTTP_POST_VARS['canread'])    ? intval($HTTP_POST_VARS['canread'])    : 0;
	$cancomment = isset($HTTP_POST_VARS['cancomment']) ? intval($HTTP_POST_VARS['cancomment']) : 0;
	$canvote    = isset($HTTP_POST_VARS['canvote'])    ? intval($HTTP_POST_VARS['canvote'])    : 0;
	$permission = $canread + $cancomment + $canvote;
	$result = PopnupBlogUtils::newApplication($HTTP_POST_VARS['title'], $HTTP_POST_VARS['desc'], $permission,$HTTP_POST_VARS['gid'],$HTTP_POST_VARS['cat_id'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['emailalias']);
	if($result == ''){
		$new_user_notify = PopnupBlogUtils::getXoopsModuleConfig('new_user_notify');
		if ( $new_user_notify == 1 ) {
			$myts =& MyTextSanitizer::getInstance();
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
		    $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
			$xoopsMailer->setFromEmail($xoopsUser->getVar("email"));
			$xoopsMailer->setFromName($xoopsConfig['sitename']);
			$subj = sprintf(_MD_POPNUPBLOG_NEWUSERREGAT,$xoopsConfig['sitename']);
			$msgs = sprintf(_MD_POPNUPBLOG_HASJUSTREG,$myts->oopsStripSlashesGPC($uname));
			$xoopsMailer->setSubject($subj);
			$xoopsMailer->setBody($msgs);
			if ( !$xoopsMailer->send() )
				echo "<br />".$xoopsMailer->getErrors();
		}
		redirect_header(XOOPS_URL.'/',1,_MD_POPNUPBLOG_APPLICATION_APPLIED);
		exit();
	}else{
		redirect_header(XOOPS_URL.'/', 2, $result);
		exit();
	}
require('footer.php');
?>